home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / ui_text.c < prev    next >
C/C++ Source or Header  |  2000-05-01  |  6KB  |  298 lines

  1. /*********************************************************************
  2.  
  3.   ui_text.c
  4.  
  5.   Functions used to retrieve text used by MAME, to aid in
  6.   translation.
  7.  
  8. *********************************************************************/
  9.  
  10. #include "driver.h"
  11. #include "ui_text.h"
  12.  
  13. struct lang_struct lang;
  14.  
  15. char *trans_text[UI_last_entry + 1];
  16.  
  17. /* All entries in this table must match the enum ordering in "ui_text.h" */
  18. const char * default_text[] =
  19. {
  20. #ifndef MESS
  21.     "MAME",
  22. #else
  23.     "MESS",
  24. #endif
  25.  
  26.     /* copyright stuff */
  27.     "Usage of emulators in conjunction with ROMs you don't own is forbidden by copyright law.",
  28.     "IF YOU ARE NOT LEGALLY ENTITLED TO PLAY \"%s\" ON THIS EMULATOR, PRESS ESC.",
  29.     "Otherwise, type OK to continue",
  30.  
  31.     /* misc stuff */
  32.     "Return to Main Menu",
  33.     "Return to Prior Menu",
  34.     "Press Any Key",
  35.     "On",
  36.     "Off",
  37.     "NA",
  38.     "INVALID",
  39.     "(none)",
  40.     "CPU",
  41.     "Address",
  42.     "Value",
  43.     "Sound",
  44.     "sound",
  45.     "stereo",
  46.     "Vector Game",
  47.     "Screen Resolution",
  48.     "Text",
  49.     "Volume",
  50.     "Relative",
  51.     "ALL CHANNELS",
  52.     "Brightness",
  53.     "Gamma",
  54.     "Vector Intensity",
  55.     "Overclock",
  56.     "ALL CPUS",
  57. #ifndef MESS
  58.     "History not available",
  59. #else
  60.     "System Info not available",
  61. #endif
  62.  
  63.     /* special characters */
  64.     "\x11",
  65.     "\x10",
  66.     "\x18",
  67.     "\x19",
  68.     "\x1a",
  69.     "\x1b",
  70.  
  71.     /* known problems */
  72. #ifndef MESS
  73.     "There are known problems with this game:",
  74. #else
  75.     "There are known problems with this system",
  76. #endif
  77.     "The colors aren't 100% accurate.",
  78.     "The colors are completely wrong.",
  79.     "The sound emulation isn't 100% accurate.",
  80.     "The game lacks sound.",
  81.     "Screen flipping in cocktail mode is not supported.",
  82. #ifndef MESS
  83.     "THIS GAME DOESN'T WORK PROPERLY",
  84. #else
  85.     "THIS SYSTEM DOESN'T WORK PROPERLY",
  86. #endif
  87.     "The game has protection which isn't fully emulated.",
  88.     "There are working clones of this game. They are:",
  89.     "Type OK to continue",
  90. #ifdef MESS
  91.     "The emulated system is a computer: ",
  92.     "The keyboard emulation may not be 100% accurate.",
  93. #endif
  94.  
  95.     /* main menu */
  96.     "Input (general)",
  97.     "Dip Switches",
  98.     "Analog Controls",
  99.     "Calibrate Joysticks",
  100.     "Bookkeeping Info",
  101. #ifndef MESS
  102.     "Input (this game)",
  103.     "Game Information",
  104.     "Game History",
  105.     "Reset Game",
  106.     "Return to Game",
  107. #else
  108.     "Input (this machine)",
  109.     "Machine Information",
  110.     "Machine Usage & History",
  111.     "Reset Machine",
  112.     "Return to Machine",
  113.     "Image Information",
  114.     "File Manager",
  115.     "Tape Control",
  116. #endif
  117.     "Cheat",
  118.     "Memory Card",
  119.  
  120.     /* input */
  121.     "Key/Joy Speed",
  122.     "Reverse",
  123.     "Sensitivity",
  124.  
  125.     /* stats */
  126.     "Tickets dispensed",
  127.     "Coin",
  128.     "(locked)",
  129.  
  130.     /* memory card */
  131.     "Load Memory Card",
  132.     "Eject Memory Card",
  133.     "Create Memory Card",
  134.     "Call Memory Card Manager (RESET)",
  135.     "Failed To Load Memory Card!",
  136.     "Load OK!",
  137.     "Memory Card Ejected!",
  138.     "Memory Card Created OK!",
  139.     "Failed To Create Memory Card!",
  140.     "(It already exists ?)",
  141.     "DAMN!! Internal Error!",
  142.  
  143.     /* cheats */
  144.     "Enable/Disable a Cheat",
  145.     "Add/Edit a Cheat",
  146.     "Start a New Cheat Search",
  147.     "Continue Search",
  148.     "View Last Results",
  149.     "Restore Previous Results",
  150.     "Configure Watchpoints",
  151.     "General Help",
  152.     "Watchpoint",
  153.     "Disabled",
  154.     "Cheats",
  155.     "Watchpoints",
  156.     "More Info",
  157.     "More Info for",
  158.     "Name",
  159.     "Description",
  160.     "Code",
  161.  
  162.     /* watchpoints */
  163.     "Number of bytes",
  164.     "Label type",
  165.     "Label",
  166.     "X position",
  167.     "Y position",
  168.     "Watch",
  169.  
  170.     NULL
  171. };
  172.  
  173. int uistring_init (void *langfile)
  174. {
  175.     /*
  176.         TODO: This routine needs to do several things:
  177.             - load an external font if needed
  178.             - determine the number of characters in the font
  179.             - deal with multibyte languages
  180.  
  181.     */
  182.  
  183.     int i;
  184.     char curline[255];
  185.     char section[255] = "\0";
  186.     char *ptr;
  187.  
  188.     /* Clear out any default strings */
  189.     for (i = 0; i <= UI_last_entry; i ++)
  190.     {
  191.         trans_text[i] = NULL;
  192.     }
  193.  
  194.     memset(&lang, 0, sizeof(lang));
  195.  
  196.     if (!langfile) return 0;
  197.  
  198.     while (osd_fgets (curline, 255, langfile) != NULL)
  199.     {
  200.         /* Ignore commented and blank lines */
  201.         if (curline[0] == ';') continue;
  202.         if (curline[0] == '\n') continue;
  203.  
  204.         if (curline[0] == '[')
  205.         {
  206.             ptr = strtok (&curline[1], "]");
  207.             /* Found a section, indicate as such */
  208.             strcpy (section, ptr);
  209.  
  210.             /* Skip to the next line */
  211.             continue;
  212.         }
  213.  
  214.         /* Parse the LangInfo section */
  215.         if (strcmp (section, "LangInfo") == 0)
  216.         {
  217.             ptr = strtok (curline, "=");
  218.             if (strcmp (ptr, "Version") == 0)
  219.             {
  220.                 ptr = strtok (NULL, "\n");
  221.                 sscanf (ptr, "%d", &lang.version);
  222.             }
  223.             else if (strcmp (ptr, "Language") == 0)
  224.             {
  225.                 ptr = strtok (NULL, "\n");
  226.                 strcpy (lang.langname, ptr);
  227.             }
  228.             else if (strcmp (ptr, "Author") == 0)
  229.             {
  230.                 ptr = strtok (NULL, "\n");
  231.                 strcpy (lang.author, ptr);
  232.             }
  233.             else if (strcmp (ptr, "Font") == 0)
  234.             {
  235.                 ptr = strtok (NULL, "\n");
  236.                 strcpy (lang.fontname, ptr);
  237.             }
  238.         }
  239.  
  240.         /* Parse the Strings section */
  241.         if (strcmp (section, "Strings") == 0)
  242.         {
  243.             /* Get all text up to the first line ending */
  244.             ptr = strtok (curline, "\n");
  245.  
  246.             /* Find a matching default string */
  247.             for (i = 0; i <= UI_last_entry; i ++)
  248.             {
  249.                 if (strcmp (curline, default_text[i]) == 0)
  250.                 {
  251.                     char transline[255];
  252.  
  253.                     /* Found a match, read next line as the translation */
  254.                     osd_fgets (transline, 255, langfile);
  255.  
  256.                     /* Get all text up to the first line ending */
  257.                     ptr = strtok (transline, "\n");
  258.  
  259.                     /* Allocate storage and copy the string */
  260.                     trans_text[i] = malloc (strlen(transline));
  261.                     strcpy (trans_text[i], transline);
  262.  
  263.                     /* Done searching */
  264.                     break;
  265.                 }
  266.             }
  267.         }
  268.     }
  269.  
  270.     /* indicate success */
  271.     return 0;
  272. }
  273.  
  274. void uistring_shutdown (void)
  275. {
  276.     int i;
  277.  
  278.     /* Deallocate storage for the strings */
  279.     for (i = 0; i <= UI_last_entry; i ++)
  280.     {
  281.         if (trans_text[i])
  282.         {
  283.             free (trans_text[i]);
  284.             trans_text[i] = NULL;
  285.         }
  286.     }
  287. }
  288.  
  289. const char * ui_getstring (int string_num)
  290. {
  291.     /* Try to use the language file strings first */
  292.     if (trans_text[string_num] != NULL)
  293.         return trans_text[string_num];
  294.     else
  295.         /* That failed, use the default strings */
  296.         return default_text[string_num];
  297. }
  298.